/**
 * 
 */
package com.yullage.ae.core;

import java.io.Serializable;

/**
 * @author Yu-chun Huang
 * 
 */
public class Path implements Serializable {
	private static final long serialVersionUID = 1L;

	private Attritioner attritioner;

	private Zone fromZone;
	private Zone toZone;
	private long numNeurons;
	private double energy;

	public Path(Zone fromZone, Zone toZone, Attritioner attritioner) {
		if (fromZone == null || toZone == null || attritioner == null) {
			throw new IllegalArgumentException();
		}

		this.fromZone = fromZone;
		this.toZone = toZone;
		this.attritioner = attritioner;
	}

	public void init() {
		energy = 0;
	}

	public Zone getFromZone() {
		return fromZone;
	}

	public Zone getToZone() {
		return toZone;
	}

	public long getNumNeurons() {
		return numNeurons;
	}

	public void setNumNeurons(long numNeurons) {
		this.numNeurons = numNeurons;
	}

	public double getEnergy() {
		return energy;
	}

	public Attritioner getAttritioner() {
		return attritioner;
	}

	public void setAttritioner(Attritioner attritioner) {
		if (attritioner == null) {
			throw new IllegalArgumentException();
		}

		this.attritioner = attritioner;
	}

	public void charge(double energy) {
		this.energy = energy;
	}

	public void discharge() {
		toZone.addEnergy(attritioner.doAttrition(numNeurons, energy));
		energy = 0;
	}
}
